<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>声明周期</title>
</head>
<body>
    <button>来个看图神器</button>
    <button>下去吧</button>
    <hr>
    <div id="root"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        //组件
        class Image extends React.Component {
            state = {
                src: 'http://api.xiaohigh.com:8090/image/random'
            }

            render(){
                return <img onClick={this.change} width="800" src={this.state.src} alt="" />
            }

            change = () => {
                this.setState({
                    src: 'http://api.xiaohigh.com:8090/image/random?d='+Date.now()
                })
            }

            //组件挂载完成   ********
            componentDidMount(){
                console.log('组件挂载完毕');
            }

            //组件将要卸载   ********
            componentWillUnmount(){
                console.log('组件将要卸载');
            }
        }

        //获取按钮
        let btns = document.querySelectorAll('button');

        //
        btns[0].onclick = function(){
            //渲染组件
            ReactDOM.render(<Image />, document.querySelector("#root"));
        }

        btns[1].onclick = function(){
            //卸载组件  unmount 卸载  component 组件  at 在  node 节点
            ReactDOM.unmountComponentAtNode(document.querySelector("#root"));
        }


        
    </script>
</body>
</html>